home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Online / Qpopper / xtnd_xlst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-01  |  1.9 KB  |  75 lines

  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/file.h>
  4. #include <sys/wait.h>
  5. #include "popper.h"
  6.  
  7. /*
  8.  *  xlst:   POP XTND function to list headers from messages
  9.  */
  10.  
  11. pop_xlst (p)
  12. POP     *   p;
  13. {
  14.     char                    buffer[MAXLINELEN];     /*  Read buffer */
  15.     MsgInfoList         *   mp;         /*  Pointer to message info list */
  16.     int min,max;
  17.     int len = strlen(p->pop_parm[2]);
  18.  
  19.     /*  Convert the first parameter into an integer */
  20.     if (p->parm_count==3)
  21.       min = max = atoi(p->pop_parm[3]);
  22.     else
  23.     {
  24.       min = 1;
  25.       max = p->msg_count;
  26.     }
  27.  
  28.  
  29.     /*  Is requested message out of range? */
  30.     if ((min < 1) || (min > p->msg_count))
  31.         return (pop_msg (p,POP_FAILURE,"Message %d does not exist.",min));
  32.  
  33.     /* yes, we can do this */
  34.     pop_msg (p,POP_SUCCESS,"xlst command accepted; headers coming.");
  35.  
  36.     for (;min<=max;min++)
  37.     {
  38.       /*  Get a pointer to the message in the message list */
  39.       mp = &p->mlp[min-1];
  40.  
  41.       /*  Is the message flagged for deletion? */
  42.       if (mp->del_flag) continue;
  43.  
  44.       /*  Position to the start of the message */
  45.       (void)fseek(p->drop, (OFF_T)mp->offset, 0);
  46.  
  47.       /*  Skip the first line (the sendmail "From" line) */
  48.       (void)fgets (buffer,MAXMSGLINELEN,p->drop);
  49.  
  50.       /*  scan until we fine the header or a blank line */
  51.       while (fgets(buffer,MAXMSGLINELEN,p->drop)) {
  52.           if (*buffer=='\n') break;
  53.           if (!strncasecmp(buffer,p->pop_parm[2],len))
  54.           {
  55.             /* found it! */
  56.             fprintf(p->output,"%d ",min);
  57.             pop_sendline (p,buffer);
  58.             while (fgets(buffer,MAXMSGLINELEN,p->drop))
  59.             {
  60.               if (*buffer!=' ' && *buffer!='\t') break;
  61.               pop_sendline(p,buffer);
  62.             }
  63.             break;
  64.           }
  65.       }
  66.   }
  67.  
  68.   /*  "." signals the end of a multi-line transmission */
  69.   (void)fputs(".\r\n",p->output);
  70.   (void)fflush(p->output);
  71.  
  72.   return(POP_SUCCESS);
  73. }
  74.  
  75.